package com.ailink.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.Lifecycle;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

@Component
public class MyComponent implements SmartLifecycle {

    @Autowired
    private MyConfig myConfig;

    @Bean
    public Object myComponentBean1() {
        return new Object();
    }

    @Bean
    public Object myComponentBean2(@Qualifier("myComponentBean1") Object myComponentBean1) {
        Object o = this.myComponentBean1();
        System.out.println(o);
        return myComponentBean1;
    }

    public MyComponent() {

    }

    @Value("${test.value:127.0.0.1}")
    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Lazy
    @Bean
    public Object myLazyBean() {
        return new Object();
    }

    @Override
    public void start() {

    }

    @Override
    public void stop() {

    }

    @Override
    public boolean isRunning() {
        return false;
    }
}
